@aparte/n8n-chat 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -16
- package/dist/cards.d.ts +25 -1
- package/dist/cdn/chunks/{chunk-F2TNPBN3.js → chunk-37ODPEBD.js} +1 -1
- package/dist/cdn/chunks/{chunk-F2TNPBN3.js.map → chunk-37ODPEBD.js.map} +1 -1
- package/dist/cdn/chunks/{chunk-XC2SVYFR.js → chunk-DEOOTEDD.js} +2 -2
- package/dist/cdn/chunks/{chunk-XC2SVYFR.js.map → chunk-DEOOTEDD.js.map} +1 -1
- package/dist/cdn/chunks/{chunk-F2QIT4NR.js → chunk-NKYV5B7Q.js} +2 -2
- package/dist/cdn/chunks/{chunk-F2QIT4NR.js.map → chunk-NKYV5B7Q.js.map} +3 -3
- package/dist/cdn/chunks/{chunk-KY2H3HIJ.js → chunk-RDVTD2YO.js} +2 -2
- package/dist/cdn/chunks/{chunk-KY2H3HIJ.js.map → chunk-RDVTD2YO.js.map} +1 -1
- package/dist/cdn/chunks/{chunk-E55C7UF2.js → chunk-U6354LAY.js} +2 -2
- package/dist/cdn/chunks/{chunk-E55C7UF2.js.map → chunk-U6354LAY.js.map} +1 -1
- package/dist/cdn/chunks/{chunk-VLHCX6EH.js → chunk-ZNUFBTZ7.js} +2 -2
- package/dist/cdn/chunks/{chunk-VLHCX6EH.js.map → chunk-ZNUFBTZ7.js.map} +1 -1
- package/dist/cdn/chunks/{de-M5OVUL5F.js → de-BCWJVDW5.js} +1 -1
- package/dist/cdn/chunks/{de-M5OVUL5F.js.map → de-BCWJVDW5.js.map} +1 -1
- package/dist/cdn/chunks/{es-JUSLSPF7.js → es-72JNODLG.js} +1 -1
- package/dist/cdn/chunks/{es-JUSLSPF7.js.map → es-72JNODLG.js.map} +1 -1
- package/dist/cdn/chunks/{fr-Z2Y3375Z.js → fr-ZKACSOY5.js} +1 -1
- package/dist/cdn/chunks/{fr-Z2Y3375Z.js.map → fr-ZKACSOY5.js.map} +1 -1
- package/dist/cdn/chunks/{highlight-ADUWBKTT.js → highlight-DG2OVLBT.js} +2 -2
- package/dist/cdn/chunks/{highlight-ADUWBKTT.js.map → highlight-DG2OVLBT.js.map} +1 -1
- package/dist/cdn/chunks/{it-N53LIIX5.js → it-SSBBMSGX.js} +1 -1
- package/dist/cdn/chunks/{it-N53LIIX5.js.map → it-SSBBMSGX.js.map} +1 -1
- package/dist/cdn/chunks/{items-GTJKLFZT.js → items-MITCIPF3.js} +2 -2
- package/dist/cdn/chunks/{items-GTJKLFZT.js.map → items-MITCIPF3.js.map} +1 -1
- package/dist/cdn/chunks/{ja-LJHMBKJ4.js → ja-NCV4Z63H.js} +1 -1
- package/dist/cdn/chunks/{ja-LJHMBKJ4.js.map → ja-NCV4Z63H.js.map} +1 -1
- package/dist/cdn/chunks/{ko-XAQOC75B.js → ko-VCNS24WV.js} +1 -1
- package/dist/cdn/chunks/{ko-XAQOC75B.js.map → ko-VCNS24WV.js.map} +1 -1
- package/dist/cdn/chunks/{link-L4C4K5GE.js → link-7JYKZK3A.js} +2 -2
- package/dist/cdn/chunks/{link-L4C4K5GE.js.map → link-7JYKZK3A.js.map} +1 -1
- package/dist/cdn/chunks/{media-EOQEOMXK.js → media-7CZBXNEK.js} +2 -2
- package/dist/cdn/chunks/{media-EOQEOMXK.js.map → media-7CZBXNEK.js.map} +1 -1
- package/dist/cdn/chunks/{order-T5L422AO.js → order-CPY2L7MI.js} +2 -2
- package/dist/cdn/chunks/{order-T5L422AO.js.map → order-CPY2L7MI.js.map} +1 -1
- package/dist/cdn/chunks/{place-UD2C3U5F.js → place-KQ3IA5IV.js} +43 -4
- package/dist/cdn/chunks/place-KQ3IA5IV.js.map +7 -0
- package/dist/cdn/chunks/{plan-JJ3Z64NU.js → plan-OKXEPKPV.js} +2 -2
- package/dist/cdn/chunks/{plan-JJ3Z64NU.js.map → plan-OKXEPKPV.js.map} +1 -1
- package/dist/cdn/chunks/{product-FNGKWEQP.js → product-ONQRJRDO.js} +7 -3
- package/dist/cdn/chunks/product-ONQRJRDO.js.map +7 -0
- package/dist/cdn/chunks/{pt-BR-KMZM3WTU.js → pt-BR-73MNA3YX.js} +1 -1
- package/dist/cdn/chunks/{pt-BR-KMZM3WTU.js.map → pt-BR-73MNA3YX.js.map} +1 -1
- package/dist/cdn/chunks/{ru-3AG5HYY2.js → ru-SCEGVTR4.js} +1 -1
- package/dist/cdn/chunks/{ru-3AG5HYY2.js.map → ru-SCEGVTR4.js.map} +1 -1
- package/dist/cdn/chunks/{score-3CGZEPWP.js → score-QF27XJUE.js} +2 -2
- package/dist/cdn/chunks/{score-3CGZEPWP.js.map → score-QF27XJUE.js.map} +1 -1
- package/dist/cdn/chunks/{stats-FGZCRFFK.js → stats-2W3GFI4P.js} +2 -2
- package/dist/cdn/chunks/{stats-FGZCRFFK.js.map → stats-2W3GFI4P.js.map} +1 -1
- package/dist/cdn/chunks/{stock-E72GAUMB.js → stock-RCVJOOH4.js} +2 -2
- package/dist/cdn/chunks/{stock-E72GAUMB.js.map → stock-RCVJOOH4.js.map} +1 -1
- package/dist/cdn/chunks/{weather-5ZNWC2WM.js → weather-NQGN2JOS.js} +2 -2
- package/dist/cdn/chunks/{weather-5ZNWC2WM.js.map → weather-NQGN2JOS.js.map} +1 -1
- package/dist/cdn/chunks/{zh-CN-DL6ZWLGA.js → zh-CN-4K6QPBRT.js} +1 -1
- package/dist/cdn/chunks/{zh-CN-DL6ZWLGA.js.map → zh-CN-4K6QPBRT.js.map} +1 -1
- package/dist/cdn/n8n-chat.js +42 -42
- package/dist/cdn/n8n-chat.js.map +4 -4
- package/dist/create-chat.d.ts +11 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/style.css +383 -370
- package/dist/theme.css +381 -368
- package/package.json +7 -7
- package/dist/cdn/chunks/place-UD2C3U5F.js.map +0 -7
- package/dist/cdn/chunks/product-FNGKWEQP.js.map +0 -7
package/README.md
CHANGED
|
@@ -27,9 +27,9 @@ weather. [See it live](https://n8n-chat.apartejs.dev).
|
|
|
27
27
|
### From a CDN — no build step
|
|
28
28
|
|
|
29
29
|
```html
|
|
30
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.
|
|
30
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.1/dist/style.css">
|
|
31
31
|
<script type="module">
|
|
32
|
-
import { createChat } from 'https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.
|
|
32
|
+
import { createChat } from 'https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.1/dist/cdn/n8n-chat.js';
|
|
33
33
|
|
|
34
34
|
createChat({ webhookUrl: 'https://your-n8n.example.com/webhook/<id>/chat' });
|
|
35
35
|
</script>
|
|
@@ -59,10 +59,10 @@ Replace the stylesheet and the import; the call stays as it is:
|
|
|
59
59
|
|
|
60
60
|
```diff
|
|
61
61
|
- <link href="https://cdn.jsdelivr.net/npm/@n8n/chat/dist/style.css" rel="stylesheet" />
|
|
62
|
-
+ <link href="https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.
|
|
62
|
+
+ <link href="https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.1/dist/style.css" rel="stylesheet" />
|
|
63
63
|
<script type="module">
|
|
64
64
|
- import { createChat } from 'https://cdn.jsdelivr.net/npm/@n8n/chat/dist/chat.bundle.es.js';
|
|
65
|
-
+ import { createChat } from 'https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.
|
|
65
|
+
+ import { createChat } from 'https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.1/dist/cdn/n8n-chat.js';
|
|
66
66
|
createChat({ webhookUrl: 'https://your-n8n.example.com/webhook/<id>/chat' });
|
|
67
67
|
</script>
|
|
68
68
|
```
|
|
@@ -110,7 +110,7 @@ memory on the agent only, n8n answers that request with an error.
|
|
|
110
110
|
| `messageComponents` | functions that draw `type: 'component'` history messages | — |
|
|
111
111
|
| `metadata` | sent with every message, as `metadata` in the trigger's output | — |
|
|
112
112
|
| `allowFileUploads`, `allowedFilesMimeTypes` | let the person attach files, and which (`'image/*,application/pdf'`, extensions too) | `false`, any |
|
|
113
|
-
| `cards` | draw the ` ```card-<name> ` blocks of an answer as [cards](#rich-cards) | `true` |
|
|
113
|
+
| `cards` | draw the ` ```card-<name> ` blocks of an answer as [cards](#rich-cards); an object gives a card its options (`{ place: { mapTiles } }`) | `true` |
|
|
114
114
|
| `setup` | `(config) => stop?`: aparté's plugins and your own cards, on this chat ([below](#your-own-cards-and-apartés-plugins)) | — |
|
|
115
115
|
| `enableMessageActions` | "Repost" and "Reuse" on the person's own messages | `false` |
|
|
116
116
|
| `disabled` | block the input (`true`, or n8n's `{ value }`) | `false` |
|
|
@@ -181,6 +181,26 @@ write JSON: it is exact every time, and a setting can turn it off for a chat tha
|
|
|
181
181
|
cards. The [shop and booking workflows](https://n8n-chat.apartejs.dev/#workflows) do it that way.
|
|
182
182
|
`cards: false` shows the blocks as code.
|
|
183
183
|
|
|
184
|
+
A card's own options go in `cards`, handed to it when it loads. The place card, for one, draws a map
|
|
185
|
+
of its own and fetches nothing; give it your map tiles and a place with `coordinates` sits on a real
|
|
186
|
+
map:
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
createChat({
|
|
190
|
+
webhookUrl: 'YOUR_PRODUCTION_URL',
|
|
191
|
+
cards: {
|
|
192
|
+
place: {
|
|
193
|
+
mapTiles: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
194
|
+
mapAttribution: '© OpenStreetMap contributors',
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Each tile is a request from the visitor's browser to that server, which is why it is your choice:
|
|
201
|
+
OpenStreetMap's tiles need no key but have [a usage policy](https://operations.osmfoundation.org/policies/tiles/)
|
|
202
|
+
against heavy traffic; MapTiler's or Stadia's take your key in the address.
|
|
203
|
+
|
|
184
204
|
## Your own cards, and aparté's plugins
|
|
185
205
|
|
|
186
206
|
The widget is built with [aparté](https://apartejs.dev), and `setup` hands you its config: anything
|
|
@@ -210,7 +230,7 @@ createChat({
|
|
|
210
230
|
```
|
|
211
231
|
|
|
212
232
|
Take `defineCard` from the widget's own module, as above, and from the same URL when you load
|
|
213
|
-
it from a CDN (`…/@aparte/n8n-chat@0.3.
|
|
233
|
+
it from a CDN (`…/@aparte/n8n-chat@0.3.1/dist/cdn/n8n-chat.js`): the card and the chat then share
|
|
214
234
|
one copy of aparté. A kit loaded from another URL keeps its cards where the chat never looks.
|
|
215
235
|
|
|
216
236
|
````md
|
|
@@ -309,11 +329,11 @@ so the page puts a fresh token in `metadata` before every message.
|
|
|
309
329
|
2. In the page:
|
|
310
330
|
|
|
311
331
|
```html
|
|
312
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.
|
|
332
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.1/dist/style.css">
|
|
313
333
|
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit"></script>
|
|
314
334
|
<div id="turnstile"></div>
|
|
315
335
|
<script type="module">
|
|
316
|
-
import { createChat } from 'https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.
|
|
336
|
+
import { createChat } from 'https://cdn.jsdelivr.net/npm/@aparte/n8n-chat@0.3.1/dist/cdn/n8n-chat.js';
|
|
317
337
|
|
|
318
338
|
// A Turnstile token is single-use and lasts five minutes: ask for a new one before each message.
|
|
319
339
|
let widgetId;
|
|
@@ -371,21 +391,56 @@ English, French, Spanish, Portuguese (Brazil), German, Italian, Russian, Japanes
|
|
|
371
391
|
Chinese (Simplified). A page downloads only the language it uses. Set `defaultLanguage`; override
|
|
372
392
|
any word of the header or the input with `i18n`; give a whole `locale` for another language.
|
|
373
393
|
|
|
374
|
-
##
|
|
394
|
+
## Colors
|
|
375
395
|
|
|
376
|
-
|
|
377
|
-
|
|
396
|
+
Your brand color, in one line. It colors the visitor's bubble, the send button, the links and the
|
|
397
|
+
button in the corner, in light and in dark:
|
|
378
398
|
|
|
379
399
|
```css
|
|
380
400
|
:root {
|
|
381
|
-
--chat--color--
|
|
382
|
-
|
|
383
|
-
|
|
401
|
+
--chat--color--secondary: #c2410c;
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Keep white text readable on it: 4.5:1 or more (n8n's own `#20b69e` gives 2.55:1, which is why the
|
|
406
|
+
default here is `#178272`). Two more lines give the chat its own surroundings:
|
|
407
|
+
|
|
408
|
+
```css
|
|
409
|
+
:root {
|
|
410
|
+
--chat--header--background: #9a3412; /* the bar with the title */
|
|
411
|
+
--chat--body--background: #fbf2ec; /* behind the messages, in light */
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
| Variable | What it changes | When unset |
|
|
416
|
+
| --- | --- | --- |
|
|
417
|
+
| `--chat--color--secondary` | your bubble, the send button, links; tints the dark surfaces | `#178272` |
|
|
418
|
+
| `--chat--color--primary` | the button in the corner, when it should differ | `--secondary`, else n8n's `#e74266` |
|
|
419
|
+
| `--chat--header--background` / `--chat--header--color` | the title bar, in light and in dark | n8n's navy / `#f2f4f8` |
|
|
420
|
+
| `--chat--body--background` | behind the messages (light) | `#f2f4f8` |
|
|
421
|
+
| `--chat--message--bot--background` / `--chat--message--user--background` | one side's bubbles | white / `--secondary` |
|
|
422
|
+
| `--chat--font-family`, `--chat--border-radius`, `--chat--window--width` / `--height` | type, corners, the window | n8n's |
|
|
423
|
+
|
|
424
|
+
Hovers are derived from the color they darken, so one color never hovers back to n8n's green.
|
|
425
|
+
|
|
426
|
+
**Dark.** `colorScheme: 'dark'` always, `'auto'` when the visitor's system is dark (n8n's widget has
|
|
427
|
+
no dark scheme). It keeps your header and tints its navy with your `--secondary`, so the line above
|
|
428
|
+
is enough. For your own dark surfaces, set aparté's variables on the widget when it is dark:
|
|
429
|
+
|
|
430
|
+
```css
|
|
431
|
+
.aparte-n8n[data-aparte-theme='dark'] { /* colorScheme: 'dark' */
|
|
432
|
+
--aparte-bg: #1a100a; /* behind the messages */
|
|
433
|
+
--aparte-surface-1: #2a1a11; /* the field, the cards */
|
|
434
|
+
--aparte-border: #4a2c1d;
|
|
435
|
+
--aparte-message-content-bg-assistant: #2c1b12;
|
|
384
436
|
}
|
|
437
|
+
/* colorScheme: 'auto': the same, inside @media (prefers-color-scheme: dark)
|
|
438
|
+
on .aparte-n8n:not([data-aparte-theme]) */
|
|
385
439
|
```
|
|
386
440
|
|
|
387
|
-
CSS written against n8n's `.chat-*` classes
|
|
388
|
-
|
|
441
|
+
A page that themed n8n's widget keeps its variables; CSS written against n8n's `.chat-*` classes
|
|
442
|
+
does not carry over. Try a color, a header and the dark scheme side by side on
|
|
443
|
+
[n8n-chat.apartejs.dev](https://n8n-chat.apartejs.dev/#demo), which writes the CSS for you. `@aparte/n8n-chat/theme.css` is the n8n
|
|
389
444
|
look alone, for a chat you compose yourself with
|
|
390
445
|
[`@aparte/runner-n8n`](https://apartejs.dev/providers/agent/n8n/) and aparté's React, Vue, Svelte
|
|
391
446
|
or Angular components, inside an `.aparte-n8n` element.
|
package/dist/cards.d.ts
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
import type { AparteConfig } from '@aparte/core';
|
|
2
|
+
import type { PlaceCardOptions } from '@aparte/plugin-cards/place';
|
|
3
|
+
/** Each card, and how to fetch it: one chunk per card in the CDN build too. */
|
|
4
|
+
declare const CARDS: {
|
|
5
|
+
weather: () => Promise<typeof import("@aparte/plugin-cards/weather")>;
|
|
6
|
+
items: () => Promise<typeof import("@aparte/plugin-cards/items")>;
|
|
7
|
+
product: () => Promise<typeof import("@aparte/plugin-cards/product")>;
|
|
8
|
+
place: () => Promise<typeof import("@aparte/plugin-cards/place")>;
|
|
9
|
+
stats: () => Promise<typeof import("@aparte/plugin-cards/stats")>;
|
|
10
|
+
order: () => Promise<typeof import("@aparte/plugin-cards/order")>;
|
|
11
|
+
stock: () => Promise<typeof import("@aparte/plugin-cards/stock")>;
|
|
12
|
+
plan: () => Promise<typeof import("@aparte/plugin-cards/plan")>;
|
|
13
|
+
score: () => Promise<typeof import("@aparte/plugin-cards/score")>;
|
|
14
|
+
media: () => Promise<typeof import("@aparte/plugin-cards/media")>;
|
|
15
|
+
link: () => Promise<typeof import("@aparte/plugin-cards/link")>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A card's own options, handed to its setup when it loads, so passing them fetches nothing
|
|
19
|
+
* early. What is about where a card's data comes from (`tool`, `map`) is not here: the
|
|
20
|
+
* widget's blocks are that.
|
|
21
|
+
*/
|
|
22
|
+
export type CardOptions = {
|
|
23
|
+
place?: Pick<PlaceCardOptions, 'mapTiles' | 'mapAttribution' | 'mapZoom' | 'currencySymbol' | 'builtIns'>;
|
|
24
|
+
} & Partial<Record<Exclude<keyof typeof CARDS, 'place'>, Record<string, unknown>>>;
|
|
2
25
|
/** Draw the card blocks in this widget's answers. Returns the function that stops it. */
|
|
3
|
-
export declare
|
|
26
|
+
export declare function setupCards(config: AparteConfig, options?: CardOptions): () => void;
|
|
27
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var f="http://www.w3.org/2000/svg";function k(u,{pad:c=.15,range:t}={}){let s=u.filter(Number.isFinite);if(s.length===0)return{line:"",area:"",points:[]};let l=s.length===1?[s[0],s[0]]:s,i=t?t[0]:Math.min(...s),x=(t?t[1]:Math.max(...s))-i,r=40,F=100/(l.length-1),e=l.map((n,d)=>[d*F,x===0?r/2:r-(c*r+(n-i)/x*(r-2*c*r))]),h=`M${e[0][0].toFixed(2)} ${e[0][1].toFixed(2)}`;for(let n=0;n<e.length-1;n++){let d=e[n-1]??e[n],p=e[n],o=e[n+1],$=e[n+2]??o,m=[p[0]+(o[0]-d[0])/6,p[1]+(o[1]-d[1])/6],b=[o[0]-($[0]-p[0])/6,o[1]-($[1]-p[1])/6];h+=` C${m[0].toFixed(2)} ${m[1].toFixed(2)} ${b[0].toFixed(2)} ${b[1].toFixed(2)} ${o[0].toFixed(2)} ${o[1].toFixed(2)}`}let A=e[e.length-1],g=`${h} L${A[0].toFixed(2)} ${r} L${e[0][0].toFixed(2)} ${r} Z`;return{line:h,area:g,points:e}}function v(u,c={}){let t=document.createElementNS(f,"svg");t.setAttribute("viewBox","0 0 100 40"),t.setAttribute("preserveAspectRatio","none"),t.setAttribute("aria-hidden","true"),t.setAttribute("focusable","false"),t.classList.add("aparte-rich-card__sparkline");for(let a of c.className?.split(/\s+/)??[])a&&t.classList.add(a);let{line:s,area:l}=k(u,c);if(!s)return t;if(c.area){let a=document.createElementNS(f,"path");a.setAttribute("d",l),a.setAttribute("class","aparte-rich-card__sparkline-area"),t.append(a)}let i=document.createElementNS(f,"path");return i.setAttribute("d",s),i.setAttribute("class","aparte-rich-card__sparkline-line"),i.setAttribute("vector-effect","non-scaling-stroke"),t.append(i),t}export{v as a};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-37ODPEBD.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../node_modules/.pnpm/@aparte+plugin-cards@0.
|
|
3
|
+
"sources": ["../../../node_modules/.pnpm/@aparte+plugin-cards@0.30.0_@aparte+core@0.30.0/node_modules/@aparte/plugin-cards/src/kit/sparkline.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * A small line chart in SVG, with no dependency: the temperature over the next hours, a\n * price over a day. Built with `createElementNS` from numbers only, so a tool's values\n * never reach a parser. Stretched to its box (`preserveAspectRatio=\"none\"`), the stroke\n * kept at its width by `vector-effect`.\n */\nconst SVG = 'http://www.w3.org/2000/svg';\n\nexport interface SparklineOptions {\n /** Extra class on the `<svg>`. */\n className?: string;\n /** Fill the area under the line (a gradient from the stroke's colour, in the sheet). */\n area?: boolean;\n /** Padding above and below the line, as a share of the height (0.15 by default). */\n pad?: number;\n /** The value range to scale against, when several charts must share one. */\n range?: [number, number];\n}\n\n/** The points of a smooth line through `values`, in a 100 × 40 box. */\nexport function sparklinePath(values: number[], { pad = 0.15, range }: SparklineOptions = {}): { line: string; area: string; points: Array<[number, number]> } {\n // A gap (`null`, `NaN`) is left out: written into the path it would stop the drawing there.\n const finite = values.filter(Number.isFinite);\n if (finite.length === 0) return { line: '', area: '', points: [] };\n // One value is a level, drawn flat across the box: a single point would draw nothing.\n const series = finite.length === 1 ? [finite[0]!, finite[0]!] : finite;\n const lo = range ? range[0] : Math.min(...finite);\n const hi = range ? range[1] : Math.max(...finite);\n const span = hi - lo;\n const h = 40;\n const step = 100 / (series.length - 1);\n // A series that does not move is a flat line through the middle, not along the floor.\n const points = series.map((v, i): [number, number] => [\n i * step,\n span === 0 ? h / 2 : h - (pad * h + ((v - lo) / span) * (h - 2 * pad * h)),\n ]);\n // A Catmull-Rom curve through the points, written as cubic Béziers.\n let line = `M${points[0]![0].toFixed(2)} ${points[0]![1].toFixed(2)}`;\n for (let i = 0; i < points.length - 1; i++) {\n const p0 = points[i - 1] ?? points[i]!;\n const p1 = points[i]!;\n const p2 = points[i + 1]!;\n const p3 = points[i + 2] ?? p2;\n const c1: [number, number] = [p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6];\n const c2: [number, number] = [p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6];\n line += ` C${c1[0].toFixed(2)} ${c1[1].toFixed(2)} ${c2[0].toFixed(2)} ${c2[1].toFixed(2)} ${p2[0].toFixed(2)} ${p2[1].toFixed(2)}`;\n }\n const last = points[points.length - 1]!;\n const area = `${line} L${last[0].toFixed(2)} ${h} L${points[0]![0].toFixed(2)} ${h} Z`;\n return { line, area, points };\n}\n\n/** The chart as an `<svg>`; decorative (`aria-hidden`), so put the numbers in text beside it. */\nexport function sparkline(values: number[], options: SparklineOptions = {}): SVGSVGElement {\n const svg = document.createElementNS(SVG, 'svg');\n svg.setAttribute('viewBox', '0 0 100 40');\n svg.setAttribute('preserveAspectRatio', 'none');\n svg.setAttribute('aria-hidden', 'true');\n svg.setAttribute('focusable', 'false');\n svg.classList.add('aparte-rich-card__sparkline');\n // The caller's own class (its own prefix is its business), added beside ours.\n for (const name of options.className?.split(/\\s+/) ?? []) if (name) svg.classList.add(name);\n const { line, area } = sparklinePath(values, options);\n if (!line) return svg;\n if (options.area) {\n const fill = document.createElementNS(SVG, 'path');\n fill.setAttribute('d', area);\n fill.setAttribute('class', 'aparte-rich-card__sparkline-area');\n svg.append(fill);\n }\n const stroke = document.createElementNS(SVG, 'path');\n stroke.setAttribute('d', line);\n stroke.setAttribute('class', 'aparte-rich-card__sparkline-line');\n stroke.setAttribute('vector-effect', 'non-scaling-stroke');\n svg.append(stroke);\n return svg;\n}\n"],
|
|
5
5
|
"mappings": "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",
|
|
6
6
|
"names": ["SVG", "sparklinePath", "values", "pad", "range", "finite", "series", "lo", "span", "h", "step", "points", "v", "i", "line", "p0", "p1", "p2", "p3", "c1", "c2", "last", "area", "sparkline", "options", "svg", "name", "fill", "stroke"]
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as i,b as p,i as l,j as g,q as e}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as i,b as p,i as l,j as g,q as e}from"./chunk-ZNUFBTZ7.js";var _="M12 2.6l2.9 5.9 6.5.95-4.7 4.6 1.1 6.5L12 17.5l-5.8 3.05 1.1-6.5-4.7-4.6 6.5-.95z",h=`<svg viewBox="0 0 120 24" xmlns="http://www.w3.org/2000/svg">${[0,24,48,72,96].map(a=>`<path transform="translate(${a} 0)" d="${_}"/>`).join("")}</svg>`;function b(a,c,{max:t=5,count:s,starsOnly:f=!1}={}){if(c===void 0||!Number.isFinite(c)||t<=0)return null;let d=Math.max(0,Math.min(t,c)),m=i("span",{class:"aparte-rich-card__stars",attrs:{"aria-hidden":"true"}},p(h,"aparte-rich-card__stars-base"),p(h,"aparte-rich-card__stars-fill"));m.style.setProperty("--aparte-rich-card-rating",`${d/t*100}%`);let n=i("span",{class:"aparte-rich-card__rating",attrs:{role:"img"}},m),o=r=>e(a.config,r,{maximumFractionDigits:1});if(!f){let r=i("span",{class:"aparte-rich-card__rating-value",attrs:{"aria-hidden":"true"}});a.bind(r,()=>o(d)),n.append(r)}if(s!==void 0&&Number.isFinite(s)){let r=i("span",{class:"aparte-rich-card__rating-count",attrs:{"aria-hidden":"true"}});a.bind(r,()=>`(${e(a.config,s,{notation:s>=1e4?"compact":"standard"})})`),n.append(r)}return a.bind(n,()=>{let r=l(a.config,"cardsRating",g.cardsRating,{value:o(d),max:o(t)});return s!==void 0&&Number.isFinite(s)?`${r}, ${l(a.config,"cardsReviews",g.cardsReviews,{count:e(a.config,s)})}`:r},"aria-label"),n}export{b as a};
|
|
2
|
+
//# sourceMappingURL=chunk-DEOOTEDD.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../node_modules/.pnpm/@aparte+plugin-cards@0.
|
|
3
|
+
"sources": ["../../../node_modules/.pnpm/@aparte+plugin-cards@0.30.0_@aparte+core@0.30.0/node_modules/@aparte/plugin-cards/src/kit/rating.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * A rating: stars filled to the value, the value, and how many reviews it averages.\n *\n * Two rows of the same five stars, the coloured one clipped to the value's width, so\n * 4.6 shows six tenths of the fifth star. Read aloud as one sentence (\"Rated 4.6 out\n * of 5, 1,284 reviews\"); the stars themselves are hidden from a screen reader.\n */\nimport type { CardContext } from './define.js';\nimport { el, glyph } from './dom.js';\nimport { formatNumber } from './format.js';\nimport { KIT_WORDS, word } from './strings.js';\n\nconst STAR = 'M12 2.6l2.9 5.9 6.5.95-4.7 4.6 1.1 6.5L12 17.5l-5.8 3.05 1.1-6.5-4.7-4.6 6.5-.95z';\nconst FIVE = `<svg viewBox=\"0 0 120 24\" xmlns=\"http://www.w3.org/2000/svg\">${[0, 24, 48, 72, 96].map((x) => `<path transform=\"translate(${x} 0)\" d=\"${STAR}\"/>`).join('')}</svg>`; // safe-attr: this package's own glyph constants and loop numbers, never data // safe-text: this package's own SVG, built from its glyph constants\n\nexport interface RatingOptions {\n /** The scale's top (5 by default). */\n max?: number;\n /** How many reviews the value averages. */\n count?: number;\n /** Leave the number out and keep the stars. */\n starsOnly?: boolean;\n}\n\n/** The rating as an element, or `null` for no value. */\nexport function rating(ctx: CardContext, value: number | undefined, { max = 5, count, starsOnly = false }: RatingOptions = {}): HTMLElement | null {\n if (value === undefined || !Number.isFinite(value) || max <= 0) return null;\n const clamped = Math.max(0, Math.min(max, value));\n const stars = el('span', { class: 'aparte-rich-card__stars', attrs: { 'aria-hidden': 'true' } },\n glyph(FIVE, 'aparte-rich-card__stars-base'),\n glyph(FIVE, 'aparte-rich-card__stars-fill'));\n stars.style.setProperty('--aparte-rich-card-rating', `${(clamped / max) * 100}%`);\n const node = el('span', { class: 'aparte-rich-card__rating', attrs: { role: 'img' } }, stars);\n const shown = (n: number) => formatNumber(ctx.config, n, { maximumFractionDigits: 1 });\n if (!starsOnly) {\n const number = el('span', { class: 'aparte-rich-card__rating-value', attrs: { 'aria-hidden': 'true' } });\n ctx.bind(number, () => shown(clamped));\n node.append(number);\n }\n if (count !== undefined && Number.isFinite(count)) {\n const reviews = el('span', { class: 'aparte-rich-card__rating-count', attrs: { 'aria-hidden': 'true' } });\n ctx.bind(reviews, () => `(${formatNumber(ctx.config, count, { notation: count >= 10_000 ? 'compact' : 'standard' })})`);\n node.append(reviews);\n }\n ctx.bind(node, () => {\n const sentence = word(ctx.config, 'cardsRating', KIT_WORDS.cardsRating, { value: shown(clamped), max: shown(max) });\n return count !== undefined && Number.isFinite(count)\n ? `${sentence}, ${word(ctx.config, 'cardsReviews', KIT_WORDS.cardsReviews, { count: formatNumber(ctx.config, count) })}`\n : sentence;\n }, 'aria-label');\n return node;\n}\n"],
|
|
5
5
|
"mappings": "oEAYA,IAAMA,EAAO,oFACPC,EAAO,gEAAgE,CAAC,EAAG,GAAI,GAAI,GAAI,EAAE,EAAE,IAAKC,GAAM,8BAA8BA,CAAC,WAAWF,CAAI,KAAK,EAAE,KAAK,EAAE,CAAC,SAYlK,SAASG,EAAOC,EAAkBC,EAA2B,CAAE,IAAAC,EAAM,EAAG,MAAAC,EAAO,UAAAC,EAAY,EAAA,EAAyB,CAAA,EAAwB,CAC/I,GAAIH,IAAU,QAAa,CAAC,OAAO,SAASA,CAAK,GAAKC,GAAO,EAAG,OAAO,KACvE,IAAMG,EAAU,KAAK,IAAI,EAAG,KAAK,IAAIH,EAAKD,CAAK,CAAC,EAC1CK,EAAQC,EAAG,OAAQ,CAAE,MAAO,0BAA2B,MAAO,CAAE,cAAe,MAAA,CAAO,EACxFC,EAAMX,EAAM,8BAA8B,EAC1CW,EAAMX,EAAM,8BAA8B,CAAA,EAC9CS,EAAM,MAAM,YAAY,4BAA6B,GAAID,EAAUH,EAAO,GAAG,GAAG,EAChF,IAAMO,EAAOF,EAAG,OAAQ,CAAE,MAAO,2BAA4B,MAAO,CAAE,KAAM,KAAA,CAAM,EAAKD,CAAK,EACtFI,EAASC,GAAcC,EAAaZ,EAAI,OAAQW,EAAG,CAAE,sBAAuB,CAAA,CAAG,EACrF,GAAI,CAACP,EAAW,CACZ,IAAMS,EAASN,EAAG,OAAQ,CAAE,MAAO,iCAAkC,MAAO,CAAE,cAAe,MAAA,CAAA,CAAU,EACvGP,EAAI,KAAKa,EAAQ,IAAMH,EAAML,CAAO,CAAC,EACrCI,EAAK,OAAOI,CAAM,CACtB,CACA,GAAIV,IAAU,QAAa,OAAO,SAASA,CAAK,EAAG,CAC/C,IAAMW,EAAUP,EAAG,OAAQ,CAAE,MAAO,iCAAkC,MAAO,CAAE,cAAe,MAAA,CAAA,CAAU,EACxGP,EAAI,KAAKc,EAAS,IAAM,IAAIF,EAAaZ,EAAI,OAAQG,EAAO,CAAE,SAAUA,GAAS,IAAS,UAAY,UAAA,CAAY,CAAC,GAAG,EACtHM,EAAK,OAAOK,CAAO,CACvB,CACA,OAAAd,EAAI,KAAKS,EAAM,IAAM,CACjB,IAAMM,EAAWC,EAAKhB,EAAI,OAAQ,cAAeiB,EAAU,YAAa,CAAE,MAAOP,EAAML,CAAO,EAAG,IAAKK,EAAMR,CAAG,CAAA,CAAG,EAClH,OAAOC,IAAU,QAAa,OAAO,SAASA,CAAK,EAC7C,GAAGY,CAAQ,KAAKC,EAAKhB,EAAI,OAAQ,eAAgBiB,EAAU,aAAc,CAAE,MAAOL,EAAaZ,EAAI,OAAQG,CAAK,CAAA,CAAG,CAAC,GACpHY,CACV,EAAG,YAAY,EACRN,CACX",
|
|
6
6
|
"names": ["STAR", "FIVE", "x", "rating", "ctx", "value", "max", "count", "starsOnly", "clamped", "stars", "el", "glyph", "node", "shown", "n", "formatNumber", "number", "reviews", "sentence", "word", "KIT_WORDS"]
|